<?php
class MembergroupAction extends CommonAction {
    public function index(){
        $map['site_id']=$this->siteid;
        $pagesize=$this->_param('pagesize')?$this->_param('pagesize'):10;
        //实例化分页类
        import('ORG.Util.Page');
        $count=D('customercategory')->where('site_id = '.$map['site_id'])->count();
        $p = new Page($count, $pagesize);
        $data = D('customercategory')->where($map)->limit($p->firstRow . ',' . $p->listRows) -> select();
        $this->assign('pid_list',$data);
        $pages = $p->show();

        $this->assign('pages', $pages);
        $this->display();
    }
    public function delete(){
        if($this->_get('id')){
            $map['pid']=$this->_get('id');
            $user=D('customercategory')->where('id in ('.$this->_get('id').')')->delete();
            if($user){
                $this->success('删除成功');
            }else{
                $this->error('删除失败');
            }
        }
    }
    public function add(){
        $map['site_id']=$this->siteid;
        $m=D('customercategory')->where($map)->select();
        $this->assign('pid_list',$m);
        $this->display();
    }
    public function edit(){
        $map['site_id']=$this->siteid;
        $map['id']=$this->_param('id');
        $m=D('customercategory')->where($map)->find();
        $this->assign('info',$m);
        $this->display();
    }

    //重写更新方法,防止用户选择自己作为父分类
    public function update(){
        $map['id']=$this->_param('id');
        $map['site_id'] =$this->siteid;
        $map['user_id'] = session(C('USER_AUTH_KEY'));
        $map['name']=$this->_param('name');
        $map['status']=$this->_param('status');
        $map['remark']=$this->_param('remark');
        $update=M('customercategory')->save($map);
        if($update){
            $this->success('修改成功',U('index'));
        }else{
            $this->error('修改失败',U('edit',array('id'=>$map['id'])));
        }
    }
    public function insert(){
        $map['site_id'] =$this->siteid;
        $map['user_id'] = session(C('USER_AUTH_KEY'));
        $map['name']=$this->_param('title');
        $map['status']=$this->_param('status');
        $map['remark']=$this->_param('remark');
        $add=M('customercategory')->add($map);
        if($add){
            $this->success('添加成功',U('index'));
        }else{
            $this->error('添加失败',U('add'));
        }
    }
}

?>